const express=require('express');
const jwt=require('jsonwebtoken');
const app=express();
app.use(express.json())

const users=[
    {
        username:'dql',
        password:'123'
    }
]
console.log(11);

app.post('/login',(req,res)=>{
    console.log('req',req.body);
    let {username='',password=''}=req.body;
    let userInfo=users.some(item=>item.username===username&&item.password===password)
    if(userInfo){
        let token=jwt.sign(req.body,'token',{expiresIn:'1h'})
        let refreshToken=jwt.sign(req.body,'refreshToken',{expiresIn:'1d'})
        res.send({
            code:200,
            message:'登陆成功',
            token,
            refreshToken
        })
    }else{
        res.send({
            code:400,
            message:'还没有注册'
        })
    }
})


app.listen(8080,()=>{
    console.log('服务启动成功8080');
})
